const app = getApp()

Page({
  data: {

  },
  onLoad: function (options) {
    var _ = this;
    _.setData({
      area: options.area,
      agent: options.agent,
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
  },
  getPhoneNumber(e) {
    var _ = this;
    var area = _.data.area;
    var agent = _.data.agent;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('gsyqphone', res.result)
      _.setData({
        mobile: res.result,
      })
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 42,
          mobile: res.result,
          areaCode: _.data.area,
          agent: _.data.agent,
          pageId: _.data.page
        },
        success: res => {

        }
      })
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/chaxun/register/?actid=47932&callback=?",
        data: {
          phone: res.result,
          isagree: true,
          area: area,
          agent: agent
        }, //接收参数
        success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
        
            wx.navigateTo({
              url: '../answer/answer',
            })
          

        }
      })
    }).catch(err => {
      console.error(err);
    });


  },
  start: function () {
    wx.navigateTo({
      url: '../answer/answer'
    });
  },
  onShareAppMessage: function (res) {
    //当监听到用户点击了分享或者拍抖音等按钮后，会执行该函数
    console.log(res.channel);
    // do something
    return {
      //执行函数后，这里是需要该函数返回的对象
      title: "中公职业性格测试",
      imageUrl: "https://sd.offcn.com/zg/wximg/2022/dy/psy/bg.jpg",
      success() {
        console.log("分享成功");
      },
      fail(e) {
        console.log("分享失败", e);
      },
    }; //返回的对象会传入tt.shareAppMessage进行最终分享
  }

})